import { createApp } from 'vue'
import App from './App.vue'
import  '@/assets/index.scss';
import { registerMicroApps, start,setDefaultMountApp } from 'qiankun';
// import microApps from "./micro-app";
import "nprogress/nprogress.css";
import store from "./store";
const instance= createApp(App).mount('#main-app');

// 注册微应用
const microApps = [
  {
    name: "microVue3",
    entry:"//localhost:7000/microVue3",
    activeRule: "/microVue3",
  },
  {
    name: "micro-vue2",
    entry:"http://localhost:7301/micro-vue2",
    activeRule: "/micro-vue2",
  },
  {
    name: "purehtml",
    entry:"http://localhost:7104/index.html",
    activeRule: "/purehtml",
  },
];
// 定义loader方法，loading改变时，将变量赋值给App.vue的data中的isLoading
// function loader(loading) {
//   if (instance.isLoading) {
//     instance.isLoading = loading
//   }
// }
const apps = microApps.map((item) => {
  return {
    ...item,
    container: "#micro-container", // 子应用挂载的div
    // loader: loader,
    props: {
      // routerBase: item.activeRule, // 下发基础路由
      getGlobalState: store.getGlobalState, // 下发getGlobalState方法
    },
  };
});
registerMicroApps(apps, {
    beforeLoad: app => {
      console.log("before load app.name====>>>>>", app.name);
    },
    beforeMount: [
      app => {
        console.log("[LifeCycle] before mount %c%s", "color: green;", app.name);
      }
    ],
    afterMount: [
      app => {
        console.log("[LifeCycle] after mount %c%s", "color: green;", app.name);
      }
    ],
    afterUnmount: [
      app => {
        console.log("[LifeCycle] after unmount %c%s", "color: green;", app.name);
      }
    ]
  });
  setDefaultMountApp("/microVue3"); // 设置默认子应用
  start();
